package com.li.sssp.server;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.li.sssp.entity.Actor;
import com.li.sssp.entity.Module;
import com.li.sssp.entity.Role;
import com.li.sssp.repository.RoleRepository;

/**
 * 权限的业务逻辑
 * @author guazi
 * @date 2017/03/13
 * @version V1.0
 */
@Service
public class RoleService {

	@Autowired
	private RoleRepository roleRepository;

	/**
	 *  获取所有Role对象
	 * @return
	 */
	public List<Role> getAll() {
		return roleRepository.findAll();
	};
	
	/**
	 * 	根据角色(Actor)获取Role相关的数据(有分页)
	 * @param actor 
  	 * @param page 页面参数
	 * @return
	 */
	public Page<Role> findByActor(Actor actor,Pageable page){
		return roleRepository.findByActor(actor,page);
	}
	
	/**
	 * 根据角色获取相关Role数据(无分页)
	 * @param actor
	 * @return
	 */
	@Transactional()
	public List<Role> findByActor(Actor actor){
		return roleRepository.findByActor(actor);
	}
	
	/**
	 * 根据角色删除
	 * @param actor
	 * @return
	 */
	@Transactional()
	public Integer DelByActor(Actor actor){
		return roleRepository.DelAllByActor(actor);
	}
	
	/**
	 * 存储role
	 * @param role
	 */
	@Transactional()
	public void save(Role role){
		
		roleRepository.saveAndFlush(role);
	}
	
	/**
	 * 根据所有参数查找是否有相同的信息
	 * @param actor
	 * @param module
	 * @param c
	 * @return
	 */
	public List<Role> findRole(Actor actor,Module module,String c){
		
		return roleRepository.findByModuleAndActor(actor, module,c);
		
	}
	
}
